package com.lagou.code.service.impl;

import com.lagou.email.service.CodeEmailService;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

@Service
public class CodeEmailServiceImpl implements CodeEmailService {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Override
    public Integer validateEmailCode(String email, String code) {
        String s = redisTemplate.opsForValue().get(email);
        System.out.println(" CodeEmailServiceImpl validateEmailCode    "+s);
        if(StringUtils.isEmpty(s)){
            return 2;
        }else{
            if(s.equals(code)){
                return 0;
            }else {
                return 1;
            }
        }
    }
}
